package com.example.spring.jpa.ast.handle;

import com.example.spring.jpa.ast.AstNode;
import com.example.spring.jpa.ast.operation.AstBracket;

/**
 * @author: orange
 * @create: 2023-07-23 18:07
 * @description:
 */
public class BracketHandle extends AbstractOperationHandle {
    private boolean match = false;
    @Override
    public boolean isMatch() {
        return this.match;
    }

    @Override
    public AstNode handle(String exp, int start) throws Exception {
        if (exp == null || exp.length() <= 1) return null;
        if (exp.charAt(0) == '('
                && exp.charAt(exp.length() - 1) == ')') {
            this.match = true;
            exp = exp.substring(1, exp.length() - 1);
            AstBracket astBracket = new AstBracket(exp);
            return astBracket;
        }
        return null;
    }

    @Override
    public String[] operations() {
        return null;
    }

    @Override
    public int order() {
        return Integer.MAX_VALUE;
    }
}
